<template>
  <div class="jbc-container">
    <jbc-menu />
    <div class="jbc-payment" v-loading="infoLoading">
      <el-breadcrumb v-if="pathList.length" style="margin-top: 5px;padding: 12px 0 20px;" :separator-icon="ArrowRight">
        <el-breadcrumb-item v-for="path in pathList" :key="path.id" :to="path.url">{{ path.name }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="jbc-box">
        <shoppingCartGoodsList title="分享订单信息" :goods-list="shopList" :count="selectCount" share></shoppingCartGoodsList>
        <div class="jbc-box-footer"><el-button color="#D6000F" :loading="loading"
            style="height: 60px;padding: 12px 50px;font-size: 20px;" @click="bindSubmit">加入购物车</el-button></div>
      </div>
    </div>
  </div>
</template>

<script setup name="share">
import { ArrowRight } from "@element-plus/icons-vue"
import { appTemplateByIdGet, appTemplateJoinGet } from '@/api/share'
import useShoppingCartStore from '@/components/webCustom/shoppingCart'
const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()
const pathList = [{ id: '1', name: '首页', url: '/' }, { id: '2', name: '分享详情' }]
const infoLoading = ref(true) // 底部信息区域是否加载
const loading = ref(false) // 底部按钮是否加载
const shopList = ref([]) // 购物车列表
const orderInfo = ref({}) // 订单信息
const selectCount = ref(0) // 商品数量

route.params.id && appTemplateByIdGet({ params: { id: route.params.id } }).then((res) => {
  console.log(res)
  orderInfo.value = res.data
  shopList.value = res.data.sellVos
  selectCount.value = res.data.sellVos.length
}).catch((err) => {
  console.log(err)
}).finally(() => {
  infoLoading.value = false
})
const bindSubmit = () => {
  loading.value = true
  appTemplateJoinGet({
    params: {
      id: route.params.id // 订单ID string-query
    }
  }).then((res) => {
    if (res.code === 0) {
      proxy.$modal.msgSuccess('成功加入购物车')
      useShoppingCartStore().init()
      nextTick(() => {
        router.push({ path: '/shoppingCart' })
      })
    }
  }).finally(() => {
    loading.value = false
  })
}
</script>

<style lang="scss" scoped>
.jbc {
  &-payment {
    margin: 0 auto;
    width: var(--box-width);
  }

  &-box {
    background-color: #FFFFFF;
    border-radius: 20px;
    box-sizing: border-box;
    padding: 30px;

    &~& {
      margin-top: 20px;
    }

    &-footer {
      margin-top: 20px;
      text-align: center;
    }
  }
}
</style>